<?php

namespace app\merchant\controller\merchant;
use app\common\controller\BaseController;
use app\common\service\merchant\MerchantShopService;
use app\common\validate\merchant\MerchantShopValidate;
use hg\apidoc\annotation as Apidoc;
/**
 * @Apidoc\Title("店铺管理")
 * @Apidoc\Group("merchant")
 * @Apidoc\Sort("250")
 */
class MerchantShop extends BaseController
{
    /**
    * @Apidoc\Title("店铺管理列表")
    * @Apidoc\Query(ref="pagingQuery")
    * @Apidoc\Query(ref="sortQuery")
    * @Apidoc\Query(ref="searchQuery")
    * @Apidoc\Query(ref="dateQuery")
    * @Apidoc\Returned(ref="expsReturn")
    * @Apidoc\Returned(ref="pagingReturn")
    * @Apidoc\Returned("list", type="array", desc="店铺管理列表", children={
    *   @Apidoc\Returned(ref="app\common\model\MerchantShopModel", field="id,title,content,is_disable,create_time,update_time,merchant_id,setting_store_platform_id,setting_store_type_id,setting_store_flag_id,flag_remark,shop_wangwang,shop_website,shop_group_title,repurchase_days,delivery_people,delivery_phone,delivery_region_id,delivery_address,is_assistant,is_mer_rebate,auth_status,auth_msg,auth_time,image_id,sort,remark")
    * })
    */
    public function list()
    {
        $where = $this->buildWhere([
            'merchant_id',
            'setting_store_platform_id',
            'setting_store_type_id',
            'is_disable',
            'auth_status'
        ]);
        $where = $this->where(where_delete($where));
        $where[] = ['merchant_id','=',mer_id()];
        $data = MerchantShopService::list($where, $this->page(), $this->limit(), $this->order());
        return success($data);
    }
    /**
    * @Apidoc\Title("店铺管理信息")
    * @Apidoc\Query(ref="app\common\model\MerchantShopModel", field="id")
    * @Apidoc\Returned(ref="app\common\model\MerchantShopModel")
    */
    public function info()
    {
        $param = $this->params(['id/d' => '']);
        validate(MerchantShopValidate::class)->scene('info')->check($param);
        $data = MerchantShopService::info($param['id']);
        return success($data);
    }
    /**
    * @Apidoc\Title("店铺管理添加")
    * @Apidoc\Method("POST")
    * @Apidoc\Param(ref="app\common\model\MerchantShopModel", field="title,content,is_disable,merchant_id,setting_store_platform_id,setting_store_type_id,setting_store_flag_id,flag_remark,shop_wangwang,shop_website,shop_group_title,repurchase_days,delivery_people,delivery_phone,delivery_region_id,delivery_address,is_assistant,is_mer_rebate,auth_status,auth_msg,auth_time,image_id,sort,remark")
    */
    public function add()
    {
        $param = $this->params(MerchantShopService::$edit_field);
        $param['merchant_id'] = mer_id();
        validate(MerchantShopValidate::class)->scene('add')->check($param);
        $data = MerchantShopService::add($param);
        return success($data);
    }
    /**
    * @Apidoc\Title("店铺管理修改")
    * @Apidoc\Method("POST")
    * @Apidoc\Param(ref="app\common\model\MerchantShopModel", field="id,title,content,is_disable,merchant_id,setting_store_platform_id,setting_store_type_id,setting_store_flag_id,flag_remark,shop_wangwang,shop_website,shop_group_title,repurchase_days,delivery_people,delivery_phone,delivery_region_id,delivery_address,is_assistant,is_mer_rebate,auth_status,auth_msg,auth_time,image_id,sort,remark")
    */
    public function edit()
    {
        $param = $this->params(MerchantShopService::$edit_field);
        $param['merchant_id'] = mer_id();
        validate(MerchantShopValidate::class)->scene('edit')->check($param);
        $data = MerchantShopService::edit($param['id'], $param);
        return success($data);
    }
    /**
    * @Apidoc\Title("店铺管理删除")
    * @Apidoc\Method("POST")
    * @Apidoc\Param(ref="idsParam")
    */
    public function dele()
    {
        $param = $this->params(['ids/a' => []]);
        validate(MerchantShopValidate::class)->scene('dele')->check($param);
        $data = MerchantShopService::dele($param['ids']);
        return success($data);
    }
    /**
     * @Apidoc\Title("店铺管理禁用")
     * @Apidoc\Method("POST")
     * @Apidoc\Param(ref="idsParam")
     * @Apidoc\Param(ref="app\common\model\MerchantShopModel", field="is_disable")
     */
    public function disable()
    {
        $param = $this->params(['ids/a' => [], 'is_disable/d' => 0]);
        validate(MerchantShopValidate::class)->scene('disable')->check($param);
        $data = MerchantShopService::edit($param['ids'], $param);
        return success($data);
    }
    /**
     * @Apidoc\Title("小助手")
     * @Apidoc\Method("POST")
     * @Apidoc\Param(ref="idsParam")
     * @Apidoc\Param(ref="app\common\model\MerchantShopModel", field="is_assistant")
     */
    public function is_assistant()
    {
        $param = $this->params(['ids/a' => [], 'is_assistant/d' => 0]);
        validate(MerchantShopValidate::class)->scene('assistant')->check($param);
        $data = MerchantShopService::edit($param['ids'], $param);
        return success($data);
    }
    /**
     * @Apidoc\Title("插旗配置")
     * @Apidoc\Method("POST")
     * @Apidoc\Param(ref="idsParam")
     * @Apidoc\Param(ref="app\common\model\MerchantShopModel", field="is_assistant")
     */
    public function flagConfig()
    {
        $param = $this->params(['id/d' =>0, 'setting_store_flag_id/d' => 0, 'flag_remark/s' => '']);
        validate(MerchantShopValidate::class)->scene('flagConfig')->check($param);
        $data = MerchantShopService::edit([$param['id']], $param);
        return success($data);
    }
    /**
     * @Apidoc\Title("修改店铺分组")
     * @Apidoc\Method("POST")
     * @Apidoc\Param(ref="idsParam")
     * @Apidoc\Param(ref="app\common\model\MerchantShopModel", field="is_assistant")
     */
    public function editGroup()
    {
        $param = $this->params(['ids/a' => [], 'shop_group_id/d' => 0]);
        validate(MerchantShopValidate::class)->scene('editGroup')->check($param);
        $data = MerchantShopService::edit($param['ids'], $param);
        return success($data);
    }

}
